#ifndef GAME_H
#define GAME_H

#include <QWidget>
#include<QTableView>
#include <QStandardItemModel>
#include<QLabel>
#include<QPushButton>
#include<QTimer>
#define QPushButton_STYTLE (QString("\
QPushButton\
{\
    font-family:Microsoft Yahei;\
    font-size:8pt;\
    color:white;\
    background-color:rgb(159, 78, 62);\
    border-radius:4px;\
}\
QPushButton:pressed\
{\
    background-color:rgb(14 , 135 , 10);\
    padding-left:2px;\
    padding-top:2px;\
}"))

#define QLabel_STYTLE (QString("\
QLabel\
{\
    font-family:Microsoft Yahei;\
    font-size:10pt;\
    color:orange;\
}"))

namespace Ui {
class game;
}

class game : public QWidget
{
    Q_OBJECT

public:
    explicit game(QWidget *parent = nullptr);
    ~game();
    void paintEvent(QPaintEvent *event);
    void timerEvent(QTimerEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void generateFood();
    void updateLengths();
    void updateTableView();
    void gameOver();
    void startGame();
    void resetGame();
    void moveSnake();
private:
    Ui::game *ui;
    QPoint snakePos;
    QTimer *timer;
    QList<QPoint> foodList;
    QList<QPoint>snakebody;
    int dir;//蛇移动的方向 1.左边 2.右边 3.上面 4.下面
    QLabel * score;
    int scores = 0;
    QPushButton * startButton;
    QStandardItemModel *model; // 用于QTableView的数据模型
     int timerId;
     bool isPaused; // 声明暂停变量
};

#endif // GAME_H
